package com.crm.service.impl.workOrderManager;

import com.crm.dao.mapper.customMapper.workOrderCustomManager.WorkOrderCustomMapper;
import com.crm.dao.mapper.customMapper.workOrderCustomManager.WorkOrderReplyCustomMapper;
import com.crm.dao.mapper.workOrderManager.WorkOrderCreditDeductRecordMapper;
import com.crm.dao.mapper.workOrderManager.WorkOrderMapper;
import com.crm.dao.mapper.workOrderManager.WorkOrderReplyMapper;
import com.crm.model.entity.workOrderManager.WorkOrder;
import com.crm.model.entity.workOrderManager.WorkOrderCreditDeductRecord;
import com.crm.model.entity.workOrderManager.WorkOrderReply;
import com.crm.model.qo.workOrderManager.WorkOrderQO;
import com.crm.model.vo.workOrderManager.WorkOrderReplyVO;
import com.crm.model.vo.workOrderManager.WorkOrderVO;
import com.crm.service.workOrderManager.WorkOrderDbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author baijian
 * @Date 2021/05/18 15:19 下午
 */
@Service
public class WorkOrderDbServiceImpl implements WorkOrderDbService {

    @Autowired
    private WorkOrderMapper workOrderMapper;

    @Autowired
    private WorkOrderReplyMapper workOrderReplyMapper;

    @Autowired
    private WorkOrderCustomMapper workOrderCustomMapper;

    @Autowired
    private WorkOrderReplyCustomMapper workOrderReplyCustomMapper;

    @Autowired
    private WorkOrderCreditDeductRecordMapper workOrderCreditDeductRecordMapper;

    /**
     * 管理模块 -- 工单管理列表
     * @param workOrderQO 工单号
     * @param order 排序
     * @param dateUnit 1本周 2本月 3本年
     * @return
     */
    @Override
    public List<WorkOrderVO> workOrderList(WorkOrderQO workOrderQO, String order, Integer dateUnit) {
        return workOrderCustomMapper.workOrderList(workOrderQO,order,dateUnit);
    }

    /**
     * 工单管理-新增工单
     * @param workOrder 工单实体类
     * @return
     */
    @Override
    public Boolean addWorkOrder(WorkOrder workOrder) {
        Boolean result = false;
        int num = workOrderMapper.insertSelective(workOrder);
        if(num>0){
            result = true;
        }
        return result;
    }

    /**
     * 工单管理-工单列表-回复工单
     * @param workOrderReply 工单实体类
     * @return
     */
    @Override
    public Boolean addWorkOrderReply(WorkOrderReply workOrderReply) {
        Boolean result = false;
        int num = workOrderReplyMapper.insertSelective(workOrderReply);
        if(num>0){
            result = true;
        }
        return result;
    }

    /**
     * 工单管理-工单列表-回复工单列表
     * @param workOrderId 工单id
     * @return
     */
    @Override
    public List<WorkOrderReplyVO> workOrderReplyList(String workOrderId) {
        List<WorkOrderReplyVO> list = workOrderReplyCustomMapper.workOrderReplyList(workOrderId);
        return list;
    }

    /**
     * 用户端-工单管理-工单详情
     * @param workOrderId 工单id
     * @return
     */
    @Override
    public WorkOrder getWorkOrderById(String workOrderId) {
        return workOrderMapper.selectByPrimaryKey(workOrderId);
    }

    /**
     * 修改工单
     * @Author renshaorong
     * @Date 2021/7/20
     * @param workOrder
     * @return
     */
    @Override
    public boolean updateByPrimaryKeySelective(WorkOrder workOrder) {
        return workOrderMapper.updateByPrimaryKeySelective(workOrder) > 0;
    }

    /**
     * 新增信用值记录表
     * @param workOrderCreditDeductRecord 信用记录
     */
    @Override
    public boolean addWorkOrderCreditDeductRecord(WorkOrderCreditDeductRecord workOrderCreditDeductRecord) {
        Boolean result = false;
        int num = workOrderCreditDeductRecordMapper.insertSelective(workOrderCreditDeductRecord);
        if(num>0){
            result = true;
        }
        return result;
    }

}
